package com.ecoolex.hotel.saas.admin.graphql;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.lang.NonNull;

import com.ecoolex.framework.modularize.api.auth.admin.AdminMemberAuthority;
import com.ecoolex.framework.modularize.api.auth.annotation.AdminAuthoritativeRegister;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module;
import com.ecoolex.framework.web.api.graphql2.annotation.QueryField;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module.Type;
import com.ecoolex.framework.web.api.graphql2.annotation.MutationField;
import com.ecoolex.hotel.saas.admin.core.AdminConstant;
import com.ecoolex.hotel.saas.entity.StoreWeixinConfig;
import com.ecoolex.hotel.saas.pojo.EditStoreWeixinConfigDTO;
import com.ecoolex.hotel.saas.ws.StoreService;

@GraphQL2Module(type = Type.Admin, description = "商户微信配置")
@AdminAuthoritativeRegister(parentKey = AdminConstant.AUTH_PROJECT_KEY,
	key = StoreWeixinConfigGraphql.AUTH,
	name = "商户微信配置",
	remark = "商户微信配置")
public class StoreWeixinConfigGraphql {

	public static final String AUTH = AdminConstant.AUTH_PROJECT_KEY + "-STORE-WEIXIN-CONFIG";
	
	private static final String AUTH_GET = AUTH + "-GET";
	
	private static final String AUTH_EDIT = AUTH + "-EDIT";
	
	@Reference
	private StoreService service;
	
	@QueryField(field = "storeWeixinConfig", description = { "商户微信配置" })
	@AdminAuthoritativeRegister(parentKey = AUTH, key = AUTH_GET, name = "商户微信配置")
	public StoreWeixinConfig get(@NonNull Integer storeId, AdminMemberAuthority user) {
		user.assertAuth(AUTH_GET);
		return service.getStoreWeixinConfig(storeId);
	}
	
	@MutationField(field = "editStoreWeixinConfig", description = "编辑商户微信配置")
	@AdminAuthoritativeRegister(parentKey = AUTH, key = AUTH_EDIT, name = "编辑商户微信配置")
	public StoreWeixinConfig edit(@NonNull EditStoreWeixinConfigDTO edit, AdminMemberAuthority user) {
		user.assertAuth(AUTH_EDIT);
		return service.editStoreWeixinConfig(edit, user.userName());
	}
}
